/*
 * Copyright (c) 2008-2021 浩瀚深度 All Rights Reserved.
 *
 * <p>FileName: ZmqServiceImpl.java</p>
 *
 * @author zz
 * @date 2024/3/26
 * @version 1.0
 * History:
 * v1.0.0 2024/3/26 Create
 */
package com.monitor.service.impl;

import com.monitor.config.DataCmdConstant;
import com.monitor.config.zmq.FlowFlag;
import com.monitor.config.zmq.FlowTotalFlag;
import com.monitor.config.zmq.JsonMsgRequestType;
import com.monitor.config.zmq.TrafficFlowFlag;
import com.monitor.entity.ZmqMsg;
import com.monitor.service.ZmqService;
import com.monitor.utils.JsonMsgHelper;
import com.monitor.utils.JsonMsgRequest;
import com.monitor.utils.ZmqClientUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>Title: ZmqServiceImpl</p>
 * <p>Description: </p>
 *
 * @author zz
 */
@Slf4j
@Service
public class ZmqServiceImpl implements ZmqService {

    @Override
    public String sendZmqMsg(ZmqMsg zmqMsg) {
        StringBuilder cmdBuffer = new StringBuilder();
        JsonMsgRequest jsonMsg = ZmqClientUtils.getJsonFlowDataRequest(JsonMsgRequestType.STATIS_LINK, zmqMsg.getSoftVer(),
                new TrafficFlowFlag(FlowFlag.PER_1MIN.getFlowFlag(), FlowTotalFlag.UPLOAD_TOTAL.getFlag()));
        cmdBuffer.append(JsonMsgHelper.convertJsonMsgRequest2Cmd(jsonMsg))
                .append(DataCmdConstant.TOKEN_LINEFEES_RETURN);
        log.info("ZMQ消息发送,地址:{},端口:{},内容;{}", zmqMsg.getServerIp(), zmqMsg.getServerPort(), cmdBuffer.toString());
        String result = ZmqClientUtils.sendMsg(zmqMsg.getServerIp(), String.valueOf(zmqMsg.getServerPort()), cmdBuffer.toString());
        return result;
    }

    public static void main(String[] args) {
        String softVer = "15.12";
        StringBuilder cmdBuffer = new StringBuilder();
        JsonMsgRequest jsonMsg = ZmqClientUtils.getJsonFlowDataRequest(JsonMsgRequestType.STATIS_LINK, softVer,
                new TrafficFlowFlag(FlowFlag.PER_1MIN.getFlowFlag(), FlowTotalFlag.UPLOAD_TOTAL.getFlag()));
        cmdBuffer.append(JsonMsgHelper.convertJsonMsgRequest2Cmd(jsonMsg))
                .append(DataCmdConstant.TOKEN_LINEFEES_RETURN);
        log.info("消息发送:" + cmdBuffer.toString());
        ZmqClientUtils.sendMsg("10.10.20.70", "6011", cmdBuffer.toString());
    }
}
